package com.celesea.auth.group.vo;

import com.celesea.auth.group.entity.Group;
import com.celesea.auth.group.v1.controller.request.PostRequest;
import com.celesea.framework.util.EnvUtil;
import com.celesea.framework.vo.DictionaryVo;
import org.springframework.beans.BeanUtils;

import java.util.List;

/**
 * @author JackYuan
 * @create 2017-12-01 11:41
 */
public class GroupVo extends Group {

    private List<DictionaryVo> users;

    public GroupVo() {

    }

    public GroupVo(PostRequest request) {
        BeanUtils.copyProperties(request, this);
        this.setCompany(EnvUtil.getCompany());
        this.users = request.getUsers();
    }

    public GroupVo(Group group) {
        BeanUtils.copyProperties(group, this);
    }

    public Group toEntity() {
        Group entity = new Group();
        BeanUtils.copyProperties(this, entity);
        return entity;
    }

    public Group toUnique() {
        Group entity = new Group();
        entity.setId(this.id);
        entity.setCode(this.getCode());
        entity.setTenantId(EnvUtil.getTenantId());
        return entity;
    }

    public List<DictionaryVo> getUsers() {
        return users;
    }

    public void setUsers(List<DictionaryVo> users) {
        this.users = users;
    }

}
